package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.MessageDao;
import com.dao.MessageDaoImpl;

import vo.SendMessage;
import vo.User;

/**
 * Servlet implementation class SendMessageServlet
 */
@WebServlet("/sendMessage.do")
public class SendMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SendMessageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获得数据
		SendMessage message=new SendMessage();
		message.setMessageTitle(request.getParameter("messageTitle"));
		message.setMessageContent(request.getParameter("messageContent"));
		message.setPriority(Integer.valueOf(request.getParameter("priority")));
		message.setUserid(((User)request.getSession().getAttribute("user")).getUserid());
		String[] id=request.getParameterValues("userid");
		Integer[] userid=new Integer[id.length];
		for(int i=0;i<id.length;i++) {
			userid[i]=Integer.valueOf(id[i]);
		}
		//创建dao
		MessageDao dao=new MessageDaoImpl();
		dao.send(message, userid);
		response.sendRedirect("checkSend.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
